import java.util.Scanner;

/**
 * @TODO
 * @Author xu
 * 2025/2/21
 */
public class Work1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入第一个数：");
        double num1 = scanner.nextDouble();

        System.out.println("请输入运算符 (+, -, *, /)：");
        char operator = scanner.next().charAt(0);

        System.out.println("请输入第二个数：");
        double num2 = scanner.nextDouble();

        double result = 0;
        try {
            switch (operator) {
                case '+':
                    result = num1 + num2;
                    break;
                case '-':
                    result = num1 - num2;
                    break;
                case '*':
                    result = num1 * num2;
                    break;
                case '/':
                    if (num2 == 0) {
                        throw new ArithmeticException("除数不能为零！");
                    }
                    result = num1 / num2;
                    break;
                default:
                    System.out.println("错误的运算符！");
                    return;
            }
            System.out.println("结果：");
            System.out.printf("%.2f %s %.2f = %.2f%n", num1, operator, num2, result);
        } catch (ArithmeticException e) {
            System.out.println(e.getMessage());
        }

        scanner.close();
    }

}
